package com.jay.lang.reflect.clazz;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

import com.jay.lang.annotation.intf.MyAnnotation1;

public class FieldCls {
	public static void main(String[] args) throws InstantiationException,
			IllegalAccessException, IllegalArgumentException,
			InvocationTargetException {
		Field[] fs = B.class.getDeclaredFields();
		B b = new B(1212121212l, 787878, Short.valueOf("29987"), (byte) 123,
				new A(), new String[] { "xxx" }, 1.2d, 1.3f);
		for (Field f : fs) {
			System.out.println("---------------------");
			System.out.println(f.getName());
			System.out.println(f.getModifiers());
			System.out.println(f.isAccessible());
			System.out.println(f.isAnnotationPresent(MyAnnotation1.class));
			System.out.println(f.isSynthetic());
			System.out.println(f.getType());
			Class t = f.getType();
			f.setAccessible(true);
			System.out.println(f.get(b));
			if (double.class.isAssignableFrom(t)) {
				System.out.println(f.getDouble(b));
			}
			if (float.class.isAssignableFrom(t)) {
				System.out.println(f.getFloat(b));
			}
			if (int.class.isAssignableFrom(t)) {
				System.out.println(f.getInt(b));
			}
			if (long.class.isAssignableFrom(t)) {
				System.out.println(f.getLong(b));
			}
			if (byte.class.isAssignableFrom(t)) {
				System.out.println(f.getByte(b));
			}
			if (short.class.isAssignableFrom(t)) {
				System.out.println(f.getShort(b));
			}
		}
	}
}

class B {
	private long l;
	int i;
	protected Short s;
	public byte b;
	A a;
	String[] ss;
	double d;
	float f = 1.2f;

	public B(long l, int i, Short s, byte b, A a, String[] ss, double d, float f) {
		super();
		this.l = l;
		this.i = i;
		this.s = s;
		this.b = b;
		this.a = a;
		this.ss = ss;
		this.d = d;
		this.f = f;
	}

}